package com.itheima.edu.info.manager.sercive;

import com.itheima.edu.info.manager.dao.BaseStudentDao;
import com.itheima.edu.info.manager.dao.OtherStudentDao;
import com.itheima.edu.info.manager.dao.StudentDao;
import com.itheima.edu.info.manager.domain.Student;
import com.itheima.edu.info.manager.factory.BaseStudentDaoFactory;

public class StudentService {

    private BaseStudentDao studentDao = BaseStudentDaoFactory.getStudentDao();
    //添加学生
    public boolean addStudent(Student stu) {

        boolean b = studentDao.addStudent(stu);

        return b;
    }
    //查询学生
    public Student[] findAllStudent() {
        Student[] students = studentDao.findAllStudent();

        return  students;

    }
    //判断学生学号是否存在
    public boolean isExists(String delId) {
        Student[] stus = studentDao.findAllStudent();
        boolean flag=false;
        if (stus!=null){
        for (int i = 0; i < stus.length; i++) {
            Student s = stus[i];
            if (s!=null&&s.getId().equals(delId)){
                    flag=true;
                }
            }
        }
       return flag;
    }
    //删除方法
    public boolean deleteStudentById(String delId) {
        boolean b = studentDao.deleteStudentById(delId);

        return b;

    }

    //修改学生
    public boolean updateStudent(String updateId, Student newStu) {
        boolean b = studentDao.updateStudent( updateId,  newStu);
        return b;

    }
}
